<?php
namespace app\common\event;
use app\common\model\Resume as ResumeModel;
use think\Exception;
class RemuseRefresh
{
	public $days=3;
	public $times=600;
	public $vip_level=[];
    public function setData($data=[])
    {
    	if(!empty($data->day)&&intval($data->day))
    		$this->days=intval($data->day);
    	if(!empty($data->time)&&intval($data->time))
    		$this->times=intval($data->time);
    	if(!empty($data->vip_level))
    		$this->vip_level=$data->vip_level;
    }
	public function run()
	{
		$Model=ResumeModel::alias('resume')->whereTime('resume.create_time','>',time()-3600*24*$this->days);
		if (!empty($this->vip_level)) {
			$Model->join('user_vip user_vip','user_vip.uid=resume.uid')
			->whereIn('user_vip.personal_vip_level',$this->vip_level);
		}
		$Data=$Model->column('resume.id');
		$updateData=[];
		foreach ($Data as $k => $v) {
			$refresh_time=rand(1,$this->times);
			$updateData[]=[
				'id'=>$v,
				'refresh_time'=>time()-$refresh_time
			];
		}
		if (!empty($updateData)) {
			$ResumeModel=new ResumeModel;
			$ResumeModel->saveAll($updateData);
		}
		return true;
	}
}